import {
  cancelOrder,
  remindShip,
  comfirmOrder
} from "../../api.js"
Component({
  properties: {
    order: Object,
    type: String
  },
  methods: {
    // 订单取消
    handleOrderCancel(e) {
      let batchcode = e.target.dataset.code
      let token = getApp().globalData.Store.token
      cancelOrder(token, batchcode).then(res => {
        if (res.data.code === 666) {
          this.triggerEvent("orderCancel", batchcode)
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        }

      })
    },
    // 未付款订单详情
    toNoPayOrderDetail(e) {
      let code = e.target.dataset.code
      wx.navigateTo({
        url: `/pages/money/submit/submit?batchcode=${code}`,
      })
    }, // 其他类型的订单详情 
    toOrderDetail(e) {
      let code = e.target.dataset.code
      wx.navigateTo({
        url: `/pages/money/detail/detail?batchcode=${code}`,
      })
    },
    // 确认收货 
    handleReceipt(e) {
      let token = getApp().globalData.Store.token
      let batchcode = e.target.dataset.code
      comfirmOrder(token, batchcode).then(res => {
        wx.showToast({
          title: res.data.msg,
          icon: "none"
        })
        this.triggerEvent("comfirm")
      })
    },
    // 提醒发货
    remindShip(e) {
      let store = getApp().globalData.Store
      let code = e.target.dataset.code
      let businessId = store.business.id
      let token = store.token
      remindShip(token, code, businessId).then(res => {
        wx.showToast({
          title: res.data.msg,
          icon: "none"
        })
      })
    }
  },
})